import 'package:flutter/material.dart';
import 'package:jdapp/widget/JdText.dart';
import 'package:jdapp/widget/JdButton.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jdapp/config/jj_domain.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:dio/dio.dart';
import 'package:jdapp/jj_home_tabs.dart';


class RegisterThirdPage extends StatefulWidget {
  Map arguments;
  RegisterThirdPage({Key? key, required this.arguments}) : super(key: key);

  _RegisterThirdPageState createState() => _RegisterThirdPageState();
}

class _RegisterThirdPageState extends State<RegisterThirdPage> {
  String code = "";
  String tel = "null";
  String password = "";
  String rpassword = "";

  void initState() {
    super.initState();
    this.code = widget.arguments["code"];
    this.tel = widget.arguments["tel"];
  }

  doRegister() async {
    if (password.length < 6) {
      Fluttertoast.showToast(
        msg: '输入长度太短',
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
      );
    } else if (password != rpassword) {
      Fluttertoast.showToast(
        msg: '输入不相等',
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
      );
    } else {
      // var api = "${JJConfig.domain}api/regiser";
      // print('1');
      // var response = await Dio().post(api, data: {
      //   "tel": this.tel,
      //   "code": this.code,
      //   "password": this.password
      // });
      // if (response.data["success"]) {
        //保存用户信息，
         //Storage.setString('userInfo', json.encode(response.data["userinfo"]));
        //返回根
         Navigator.of(context).pushAndRemoveUntil(
            new MaterialPageRoute(builder: (context) => new Tabs()),
            (route) => route == null);
       // print('chenhggong');
      // } else {
      //   print("shiabi");
      //   Fluttertoast.showToast(
      //     msg: "注册失败",
      //     toastLength: Toast.LENGTH_SHORT,
      //     gravity: ToastGravity.CENTER,
      //   );
      // }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("用户注册-第三步"),
      ),
      body: Container(
        padding: EdgeInsets.all(20),
        child: ListView(
          children: <Widget>[
            SizedBox(height: 50),
            JdText(
              text: "请输入密码",
              password: true,
              onChanged: (value) {
                this.password = value;
              },
            ),
            SizedBox(height: 10),
            JdText(
              text: "请输入确认密码",
              password: true,
              onChanged: (value) {
                this.rpassword = value;
              },
            ),
            SizedBox(height: 20),
            JdButton(
              text: "登录",
              color: Colors.red,
              // height: 74,
              cb: doRegister,
            )
          ],
        ),
      ),
    );
  }
}
